Skip to content

change database and add users table schema - #1

Merged
sobhaann merged 1 commit into
masterfrom
drop-sqlite-and-create-user-schema
Jul 5, 2026
Merged

sobhaann merged 1 commit into
masterfrom
drop-sqlite-and-create-user-schema

Conversation

@sobhaann

@sobhaann sobhaann commented Jul 4, 2026 •

Copy link
Copy Markdown
Owner

drop sqlite for postgres because it has more features for uuid and create docker compose file for postgres image

Summary by CodeRabbit

  • New Features
    • Added PostgreSQL support with containerized deployment and persistent database storage.
    • Introduced a users data layer with queries for listing users and fetching by identifier or email.
  • Bug Fixes
    • Improved JWT handling to use the correct secret and subject identifier when issuing and validating tokens.
  • Documentation
    • Updated technology stack documentation and expanded the configuration example for server and auth settings.
  • Chores
    • Updated ignore rules and removed an outdated shortcut for running the app.

@coderabbitai

coderabbitai Bot commented Jul 4, 2026 •

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

This PR moves the project to PostgreSQL, adds the users schema and queries, updates JWT validation to use the configured secret, and refreshes docs, config examples, ignore rules, and build files.

Changes

PostgreSQL migration

Layer / File(s) Summary
PostgreSQL tooling and driver setup
docker-compose.yml, sqlc.yaml, go.mod
Adds a PostgreSQL compose service with secrets and persistence, switches sqlc to PostgreSQL/pgx-v5, and adds pgx-related dependencies.
Users schema and queries
sql/schema/001_users.sql, sql/queries/users.sql
Adds the users table migration and named queries for listing users and selecting by r_id or email while excluding soft-deleted rows.
JWT subject handling
internal/auth/jwt.go
Renames the JWT subject variable to userRID and uses the configured HMAC secret during validation.
Docs, config, and ignore updates
README.md, config/config.toml.example, config/config.toml, .gitignore, makefile
Updates the README, adds an example config, removes the existing config contents, adds ignore rules, and removes the Makefile run target.

Estimated code review effort: 3 (Moderate) | ~25 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: switching databases and adding the users table schema.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch drop-sqlite-and-create-user-schema

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@sobhaann
sobhaann force-pushed the drop-sqlite-and-create-user-schema branch from 5abfafd to 080049d Compare July 4, 2026 12:42

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 4

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@docker-compose.yml`:
- Around line 3-5: The Postgres service is mounting db_data to the wrong data
directory, so the named volume is not being used by postgres:18.4-alpine3.24.
Update the volume mapping in the docker-compose service to target Postgres 18’s
actual data path under /var/lib/postgresql/18/docker, using the existing db_data
volume entry so the container persists state correctly.

In `@README.md`:
- Line 2: The TECH STACK entry in the README still lists MariaDB, which
conflicts with the PostgreSQL migration in this PR. Update the README’s database
value to PostgreSQL so the documented stack matches the actual implementation
and keep the change limited to the existing TECH STACK entry.

In `@sql/schema/001_users.sql`:
- Line 7: The users table definition currently leaves r_id nullable and
unconstrained, so duplicate external IDs can slip in and SelectUserByRID may
return an arbitrary row. Update the schema in the users table DDL to make r_id
NOT NULL and add a UNIQUE constraint (or unique index) on r_id, keeping the
change localized to the column definition used by the user lookup flow.
- Around line 2-9: The users table definition uses a plain integer primary key
for users.id, which requires callers to supply values manually. Update the users
schema so the id column uses an identity-generated primary key in the create
table users statement, keeping the rest of the columns unchanged and ensuring
inserts can omit id safely.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 7a1ea9a5-9c13-4873-a260-44c5a0ba9884

📥 Commits

Reviewing files that changed from the base of the PR and between b2329de and 5abfafd.

⛔ Files ignored due to path filters (1)
  • go.sum is excluded by !**/*.sum
📒 Files selected for processing (9)
  • .gitignore
  • README.md
  • docker-compose.yml
  • go.mod
  • internal/auth/jwt.go
  • makefile
  • sql/queries/users.sql
  • sql/schema/001_users.sql
  • sqlc.yaml
💤 Files with no reviewable changes (1)
  • makefile

Comment thread docker-compose.yml Outdated
Comment thread README.md Outdated
Comment thread sql/schema/001_users.sql
Comment thread sql/schema/001_users.sql Outdated
@sobhaann
sobhaann force-pushed the drop-sqlite-and-create-user-schema branch from 080049d to 4e15193 Compare July 4, 2026 12:44
@sobhaann
sobhaann force-pushed the drop-sqlite-and-create-user-schema branch from 4e15193 to 5e06d6c Compare July 5, 2026 07:05
@sobhaann
sobhaann merged commit a7b1b88 into master Jul 5, 2026
1 check was pending

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
internal/auth/jwt.go (1)

45-50: 🎯 Functional Correctness | 🔴 Critical | ⚡ Quick win

Pass jwt.RegisteredClaims by pointer to ParseWithClaims.
ParseWithClaims needs writable claim storage; the current value form makes valid tokens fail JSON decoding. Use &jwt.RegisteredClaims{} (or a named claims pointer) and read the subject from that instance.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@internal/auth/jwt.go` around lines 45 - 50, `ParseWithClaims` is being called
with `jwt.RegisteredClaims` by value in `jwt.ParseWithClaims`, which prevents
the claims from being populated correctly. Update the token parsing in the auth
JWT flow to pass a pointer to `jwt.RegisteredClaims` (for example via a named
claims variable) and then read the subject from that parsed claims instance
instead of the zero-value copy.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Outside diff comments:
In `@internal/auth/jwt.go`:
- Around line 45-50: `ParseWithClaims` is being called with
`jwt.RegisteredClaims` by value in `jwt.ParseWithClaims`, which prevents the
claims from being populated correctly. Update the token parsing in the auth JWT
flow to pass a pointer to `jwt.RegisteredClaims` (for example via a named claims
variable) and then read the subject from that parsed claims instance instead of
the zero-value copy.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 1ee9ad53-28cf-41d7-a573-a2a53e387cf7

📥 Commits

Reviewing files that changed from the base of the PR and between 5abfafd and 5e06d6c.

⛔ Files ignored due to path filters (1)
  • go.sum is excluded by !**/*.sum
📒 Files selected for processing (11)
  • .gitignore
  • README.md
  • config/config.toml
  • config/config.toml.example
  • docker-compose.yml
  • go.mod
  • internal/auth/jwt.go
  • makefile
  • sql/queries/users.sql
  • sql/schema/001_users.sql
  • sqlc.yaml
💤 Files with no reviewable changes (2)
  • makefile
  • config/config.toml
✅ Files skipped from review due to trivial changes (4)
  • README.md
  • config/config.toml.example
  • .gitignore
  • go.mod
🚧 Files skipped from review as they are similar to previous changes (4)
  • sqlc.yaml
  • sql/queries/users.sql
  • sql/schema/001_users.sql
  • docker-compose.yml

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant